package org.noote.LineDetection;

import org.noote.libs.graphicbuffer.GraphicView;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Point;

public class Graphic2DView extends GraphicView {
	
	public Graphic2DView(Context context) {
        super(context);
    }
	
	@Override
	protected void onSizeChanged(int width, int height, int width_old, int height_old)
	{
		super.onSizeChanged(width, height, width_old, height_old);

		createBuffer(width, height);
	    
	    drawPixels();
	}

	@SuppressWarnings("unused")
	private void test1()
	{
		_buffer._draw_fill_rect(new Point(130, 130), new Point(75, 80), Color.CYAN);
	}
	@SuppressWarnings("unused")
	private void test2()
	{
		_buffer._draw_fill_rect(new Point(30, 30), new Point(75, 80), Color.CYAN);
		_buffer._draw_fill_rect(new Point(75, 15), new Point(120, 60), Color.DKGRAY);
		_buffer._draw_fill_rect(new Point(145, 50), new Point(40, 40), Color.LTGRAY);
		_buffer._draw_fill_rect(new Point(205, 80), new Point(50, 80), Color.MAGENTA);
		_buffer._draw_fill_rect(new Point(60, 180), new Point(150, 20), Color.YELLOW);
	}
	@SuppressWarnings("unused")
	private void test3()
	{
		for(int j=0; j<75; j++)
		{
			_buffer._draw_horizontal_line(250+j/4, 125+j, 150+j/2, Color.GREEN);				
		}
	}
	private void test4()
	{
		_buffer._draw_fill_rect(new Point(0, 0), new Point(50, _buffer.getHeight()), Color.BLUE);
		_buffer._draw_fill_rect(new Point(50, 0), new Point(50, _buffer.getHeight()), Color.RED);
		_buffer._draw_fill_rect(new Point(_buffer.getWidth()-50, 0), new Point(50, _buffer.getHeight()), Color.WHITE);

		_buffer._draw_fill_rect(new Point(0, 0), new Point(_buffer.getWidth(), 50), Color.BLUE);
		_buffer._draw_fill_rect(new Point(0, 50), new Point(_buffer.getWidth(), 50), Color.RED);

		_buffer._draw_fill_rect(new Point(30, 30), new Point(75, 80), Color.CYAN);
		_buffer._draw_fill_rect(new Point(75, 15), new Point(120, 60), Color.DKGRAY);
		_buffer._draw_fill_rect(new Point(145, 50), new Point(40, 40), Color.LTGRAY);
		_buffer._draw_fill_rect(new Point(205, 80), new Point(50, 80), Color.MAGENTA);
		_buffer._draw_fill_rect(new Point(60, 180), new Point(150, 20), Color.YELLOW);
		
		for(int j=0; j<75; j++)
		{
			_buffer._draw_horizontal_line(250+j/4, 125+j, 150+j/2, Color.GREEN);				
		}
	}
	
	private void drawPixels()
	{
		//test1();
		//test2();
		//test3();
		test4();
		
		refresh();
	}
	
	public void copy_into(LineDetection detect)
	{
		if(_buffer != null)
		{
			detect.copy_from(_buffer.getBuffer(), _buffer.getWidth(), _buffer.getHeight());
		}
	}
}
